Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monetized_attributes class discrepancy #681

Merged

Conversation

Neilos
Copy link
Contributor

@Neilos Neilos commented Nov 27, 2023

Suppose we have a model

class Investment < ActiveRecord::Base
  monetize :value
  monetize :discounted_value
end

and a subclass

class BadInvestment < Investment
end

When we check the monetized_attributes of both the Product and SpecialProduct we get seemingly the same result:

Investment.monetized_attributes
# => {
  'value' => 'value_cents',
  'discounted_value' => 'discounted_value_cents',
}

BadInvestment.monetized_attributes
# => {
  'value' => 'value_cents',
  'discounted_value' => 'discounted_value_cents',
}

...but when we check the class of the monetized_attributes we can see that one is a ActiveSupport::HashWithIndifferentAccess while the other is a Hash.

Investment.monetized_attributes.class
# => ActiveSupport::HashWithIndifferentAccess

BadInvestment.monetized_attributes
# => Hash

This pull request fixes the discrepancy, ensuring both are a ActiveSupport::HashWithIndifferentAccess.

Suppose we have a model

```ruby
class Investment < ActiveRecord::Base
  monetize :value
  monetize :discounted_value
end
```

and a subclass

```ruby
class BadInvestment < Investment
end
```

When we check the monetized_attributes of both the `Product` and `SpecialProduct` we get seemingly the same result:

```ruby
Investment.monetized_attributes
# => {
  value: value_cents,
  discounted_value: discounted_value_cents,
}

BadInvestment.monetized_attributes
# => {
  value: value_cents,
  discounted_value: discounted_value_cents,
}
```

...but when we check the class of the `monetized_attributes` we can see that one is a `ActiveSupport::HashWithIndifferentAccess` while the other is a `Hash`.

This commit fixes the discrepancy, ensuring both are a `ActiveSupport::HashWithIndifferentAccess`.
@Neilos Neilos marked this pull request as ready for review November 27, 2023 16:35
Copy link
Contributor

@sunny sunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Could you add a line to the CHANGELOG under a new ## unreleased section as well? 🙏🏻

@semmons99 semmons99 merged commit 44def3e into RubyMoney:main Mar 13, 2024
3 of 5 checks passed
@semmons99
Copy link
Member

ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants